home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-04 | 3.9 KB | 154 lines | [TEXT/KAHL] |
- /***************************************************** IMPLEMENTATION
- DATE: 10/5/93
- AUTHOR: Eric R. Rosé
-
- CLASS: CPPDRequest
-
- SUPERCLASS: CPPWindow
-
- This C++ class manages a general request window
-
- ********************************************************************/
-
- #include <CPPDRequest.h>
- #include <CPPWindowManager.h>
- #include <CPPButton.h>
- #include <CPPDialogText.h>
- #include <CPPStaticText.h>
- #include <ToolboxTools.h>
-
- /*-----------------------------------------------------------------*/
- /*-------------------------- GLOBALS ------------------------------*/
- /*-----------------------------------------------------------------*/
-
- Rect DRequestBounds = {40, 40, 181, 368};
-
- extern CPPWindowManager *gWindowManager;
- extern void DoStdOKButton (CPPWindow *theWindow);
- extern void DoStdCancelButton (CPPWindow *theWindow);
-
- /*-----------------------------------------------------------------*/
- /*------------------------ PUBLIC METHODS -------------------------*/
- /*-----------------------------------------------------------------*/
-
- CPPDRequest::CPPDRequest (CPPWindowManager *theManager,
- StringPtr Prompt, StringPtr DefaultReply) :
- CPPWindow (theManager, &DRequestBounds, "\pDRequest",
- TRUE, dBoxProc, FALSE, 13, TRUE, TRUE,
- systemFont, 12)
- {
- Rect tempRect;
- CPPStaticText *ST;
-
- SetRect (&tempRect, 8, 8, 299, 57);
- ST = new CPPStaticText ((CPPWindow *)this, &tempRect, Prompt,
- systemFont, 12, teJustLeft);
-
- SetRect (&tempRect, 8, 66, 299, 100);
- reply = new CPPDialogText ((CPPWindow *)this, &tempRect,
- DefaultReply, 255, systemFont, 12);
-
- SetRect (&tempRect, 220, 113, 295, 133);
- okButton = new CPPButton ((CPPWindow *)this, &tempRect, "\pOK",
- TRUE, FALSE, FALSE, TRUE, TRUE);
- okButton->SetDoClickProc (DoStdOKButton);
-
- SetRect (&tempRect, 8, 113, 83, 133);
- cancelButton = new CPPButton ((CPPWindow *)this, &tempRect, "\pCancel",
- FALSE, FALSE, FALSE, TRUE, TRUE);
- cancelButton->SetDoClickProc (DoStdCancelButton);
-
- MakeTarget (reply);
-
- }
-
- /*-----------------------------------------------------------------*/
-
- CPPDRequest::~CPPDRequest ()
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- char *CPPDRequest::ClassName (void)
- {
- return "CPPDRequest";
- }
-
- /*-----------------------------------------------------------------*/
-
- StringPtr CPPDRequest::GetDialogData (void)
- /* return the text of the reply string */
- {
- if (reply)
- return reply->GetAsString();
- else
- return NULL;
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPDRequest::DoUserKey (EventRecord *theEvent)
- {
- char theKey;
-
- theKey = theEvent->message & charCodeMask;
- if (!(theEvent->modifiers & cmdKey))
- {
- switch (theKey) {
- case kTab :
- return TRUE;
- break;
- case kEscape :
- if (cancelButton)
- cancelButton->SimulateClick();
- return TRUE;
- break;
- case kEnter :
- case kReturn :
- if (okButton)
- okButton->SimulateClick();
- return TRUE;
- break;
- default:
- return CPPWindow::DoUserKey (theEvent);
- break;
- } // switch
- }
- else
- {
- if (theKey == '.')
- {
- if (cancelButton)
- cancelButton->SimulateClick();
- return TRUE;
- }
- else
- return CPPWindow::DoUserKey (theEvent);
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean DoRequest (StringPtr Prompt, StringPtr Default, StringPtr *Reply)
- {
- CPPDRequest *theWindow;
- Boolean theResult;
-
- theWindow = new CPPDRequest (gWindowManager, Prompt, Default);
-
- if (theWindow)
- {
- theWindow->DoModalWindow ();
- if ((theResult = theWindow->modalResult))
- *Reply = theWindow->GetDialogData ();
- delete theWindow;
- return theResult;
- }
- else
- {
- ErrorAlert (MemError(), "\pCould not display the 'request' dialog");
- return FALSE;
- }
- }